
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 1
 * @Author : WangRuoyu 
 * @Date : 2023/5/18 19:07
 */

#include "iostream"

using namespace std;

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    bool st[n + 1];
    st[0] = true;
    for (int i = 0; i <= n; ++i) {
        st[i] = false;
    }

    int res = 0;
    for (int i = 0; i < k; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        if (!st[y]) res++;
        st[x] = true;
    }

    printf("%d", res);

    return 0;
}